﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace PanoramicData.TickTockBlink
{
	internal static class TimeColorHelper
	{
		private static readonly Dictionary<int, Color> HourColorMapping = new Dictionary<int, Color>
			                                                         {
				                                                         {0, Color.MidnightBlue},
				                                                         {1, Color.Black},
				                                                         {2, Color.Black},
				                                                         {3, Color.Black},
				                                                         {4, Color.Black},
				                                                         {5, Color.Black},
				                                                         {6, Color.Black},
				                                                         {7, Color.Black},
				                                                         {8, Color.DarkRed},
				                                                         {9, Color.Red},
				                                                         {10, Color.DarkOrange},
				                                                         {11, Color.Yellow},
				                                                         {12, Color.DarkGreen},
				                                                         {13, Color.LightGreen},
				                                                         {14, Color.DarkCyan},
				                                                         {15, Color.LightCyan},
				                                                         {16, Color.DarkBlue},
				                                                         {17, Color.LightBlue},
				                                                         {18, Color.DarkMagenta},
				                                                         {19, Color.Magenta},
				                                                         {20, Color.Gray},
				                                                         {21, Color.White},
				                                                         {22, Color.Black},
				                                                         {23, Color.Black},
			                                                         };

		public static Color GetColor(DateTime dateTime)
		{
			var startColor = HourColorMapping[dateTime.Hour];
			var endColor = HourColorMapping[(dateTime.Hour + 1)%24];
			var minute = dateTime.Minute;

			var red = startColor.R + (endColor.R - startColor.R) * minute / 60;
			var green = startColor.G + (endColor.G - startColor.G) * minute / 60;
			var blue = startColor.B + (endColor.B - startColor.B) * minute / 60;
			return Color.FromArgb(red, green, blue);
		}

		public static FlashType GetFlashType(DateTime dateTime)
		{
			if(dateTime.Second != 0) return FlashType.None;
			switch (dateTime.Minute)
			{
				case 0:
					return FlashType.Double;
				case 15:
				case 30:
				case 45:
					return FlashType.Single;
				default:
					return FlashType.None;
			}
		}
	}
}
